package com.tensquare.qa.service;

import com.tensquare.qa.dao.ProblemDao;
import com.tensquare.qa.pojo.Problem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import util.IdWorker;

@Service
public class ProblemService {

    @Autowired
    private ProblemDao problemDao;

    @Autowired
    private IdWorker idWorker;

    public Page<Problem> newlist(String labelid,int page,int rows){
        Pageable pageable = PageRequest.of(page-1,rows);
        return problemDao.newList(labelid,pageable);
    }

    public Page<Problem> hotlist(String labelid,int page,int rows){
        Pageable pageable = PageRequest.of(page-1,rows);
        return problemDao.hotlist(labelid,pageable);
    }

    public Page<Problem> waitlist(String labelid,int page,int rows){
        Pageable pageable = PageRequest.of(page-1,rows);
        return problemDao.waitlist(labelid,pageable);
    }

    public void add(Problem problem) {
        problem.setId(idWorker.nextId()+"");
        problemDao.save(problem);
    }

    public void update(Problem problem) {
        problemDao.save(problem);
    }

    public void deleteById(String id) {
        problemDao.deleteById(id);
    }
}
